#include<bits/stdc++.h>
#define EPS 1e-9
#define pii pair<int,int>
#define x first
#define y second
#define D double
#define pb push_back
using namespace std;
const int N = 1e5 + 7, M = 1e6 + 7;
int rd(){
    char c = getchar();
    int res = 0,f = 1;
    while(!isdigit(c)){
        if(c=='-') f = -1;
        c = getchar();
    }
    while(isdigit(c)){
        res = res * 10 + c - '0';
        c = getchar();
    }
    return res * f;
}
int n,m,L,V;
int p[N];
vector<pii>a[N];
int c[M];
int lowbit(int x){return x&(-x);}
void add(int x,int y){
    x++;
    for(;x<M;x+=lowbit(x)) c[x] += y;
}
int ask(int x){
    x++;
    int res = 0;
    for(;x;x-=lowbit(x)) res += c[x];
    return res;
}
int cnt[M];
void solve(){
    n = rd();m = rd();L = rd();V = rd();
    for(int i=1;i<=m;++i) a[i].clear();
    memset(c,0,sizeof c);
    memset(cnt,0,sizeof cnt);
    vector<pii>vec;
    for(int i=1;i<=n;++i){
        int d = rd();
        int v = rd();
        int aa = rd();
        int l = d,r = L;
        if(aa==0){
            if(v>V) l = d,r = L;
            else r = -1;
        }
        else if(aa>0){
            if(v>V) l = d,r = L;
            else if(v*v+2ll*aa*(L-d)>V*V){
                D tmp = (D)((V+EPS)*(V+EPS)-v*v) / 2.0 / aa;
                l = d + (int)ceil(tmp), r = L;
            }
            else r = -1;
        }
        else{
            if(v<=V) l = 0,r = -1;
            else{
                l = d;
                D tmp = (D)((V+EPS)*(V+EPS)-v*v) / 2.0 / aa;
                r = d + (int)floor(tmp);
                r = min(r,L);
            }
        }
        if(l<=r) vec.push_back({l,r});
    }
    for(int i=1;i<=m;++i){
        p[i] = rd();
        cnt[p[i]]++;
    }
    for(int i=1;i<=L;++i) cnt[i] += cnt[i-1];
    int ans = 0,res = 0;
    for(auto cc:vec){
        int tt = cnt[cc.y];
        if(cc.x) tt -= cnt[cc.x-1];
        if(tt){
            ans++;
            int pos = upper_bound(p+1,p+m+1,cc.y)-p-1;
            a[pos].push_back(cc);
        }
    }
    for(int i=1;i<=m;++i){
        bool ff = 0;
        for(auto cc:a[i]){
            int tt = ask(cc.y) - ask(cc.x-1);
            if(!tt){
                ff = 1;
                break;
            }
        }
        if(ff) res++,add(p[i],1);
    }
    cout<<ans<<' '<<m - res<<'\n';
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int T = rd();
    while(T--) solve();
    return 0;
}
